#pragma once

#include "effectbase.h"
#include <osg\Vec4>
#include <osg\NodeCallback>
#include <osgAnimation\EaseMotion>
#include <osg\Material>

namespace VrDataCore
{
	class FadeCallback;
	class VRDATACORE_EXPORT FadeEffect:public EffectBase
	{
	public:
		FadeEffect();
	public:
		virtual void buildPropertyMap();
		virtual void apply(CoreBase::ActorBase* actor);
		virtual void unApply(CoreBase::ActorBase* actor);
		void update();
		void fadeIn(bool in);
		bool isUpdating();
	protected:
		~FadeEffect();
		bool													_fadeIn;
		osg::Vec4												_materialEffect;
		osg::ref_ptr<FadeCallback>								_fadeCallback;
		osg::ref_ptr<osgAnimation::InOutCubicMotion>			_motion;
		bool													_updateA;
		QVector<osg::ref_ptr<osg::Material>>					_materialVector;
	};

	class FadeCallback:public osg::NodeCallback
	{
	public:
		FadeCallback(FadeEffect* fade):_fadeEffect(NULL)
		{
			_fadeEffect = fade;
		}
		virtual void operator()(osg::Node* node,osg::NodeVisitor* nv)
		{
			if(_fadeEffect!=NULL)
			{
				_fadeEffect->update();
			}
			traverse(node,nv);
		}
	protected:
		FadeEffect*												_fadeEffect;
	};
}